package com.AC.ACSougou;

import org.junit.Test;

/**
 * 搜狗第一题
 */
public class test1 {

    int max;

    int[][][] dp;

    public int recur(int a, int b, int c){
        if(dp[a][b][c] != 0)
            return dp[a][b][c];

        if(a == b && b == c){
            max = a;
            dp[a][b][c] = max;
            return max;
        }


        if(getMax(a,b,c) - getMin(a,b,c) < 3){
            max = getMin(a,b,c);
            dp[a][b][c] = max;
            return max;
        }

        if(a == getMax(a,b,c))
            max = Math.max(max, Math.max(recur(a - 2, b + 1, c),
                    recur(a - 2, b , c + 1)));
        else if(b == getMax(a,b,c))
            max = Math.max(max, Math.max(recur(a + 1, b - 2, c),
                    recur(a , b - 2, c + 1)));
        else if(c == getMax(a,b,c))
            max = Math.max(max, Math.max(recur(a + 1, b , c),
                    recur(a + 1, b , c - 2)));

        dp[a][b][c] = max;

        return max;
    }

    public int numberofprize (int a, int b, int c) {
        int n = getMax(a,b,c);
        dp = new int[n+1][n+1][n+1];
        return recur(a, b, c);
    }

    public int getMax(int a, int b, int c){
        return Math.max(Math.max(a, b), c);
    }

    public int getMin(int a, int b, int c){
        return Math.min(Math.min(a, b), c);
    }

    @Test
    public void test(){
        System.out.println(numberofprize(100,3,3));
    }
}
